﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 系统配置主表 数据类
    /// </summary>
    public class Config
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public Config()
        {
        }


        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-03</date>
        /// </summary>
        /// <param name="keyName">关键字</param>
        /// <param name="configClass">配置类别</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public ElingOA6_DSJCJ.Model.Config GetModel(string keyName, string configClass, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FKeyName,FConfigClass,FEntityNo,FDesc,FKeyValue,FIsWithDocCls,FShowText,FSeq,FIsUse from t_Config ");
            strSql.Append(" where FKeyName=@FKeyName and FConfigClass=@FConfigClass and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FKeyName", SqlDbType.NVarChar,50),
					new SqlParameter("@FConfigClass", SqlDbType.Char,2),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			};
            parameters[0].Value = keyName;
            parameters[1].Value = configClass;
            parameters[2].Value = entityNo;

            ElingOA6_DSJCJ.Model.Config model = new ElingOA6_DSJCJ.Model.Config();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得全部启用的数据列表
        /// <creator>wangl</creator>
        /// <date>2013-09-03</date>
        /// </summary>
        /// <param name="configClass">配置类别</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>列表</returns>
        public DataSet GetListAllIsUse(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FKeyName,FConfigClass,FEntityNo,FDesc,FKeyValue,FIsWithDocCls,FShowText,FSeq,FIsUse ");
            strSql.Append(" FROM t_Config ");
            strSql.Append(" where FEntityNo=@FEntityNo AND FIsUse='Y' ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			
                                        };
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-03</date>
        /// </summary>
        /// <param name="row">DataRow对象</param>
        /// <returns></returns>
        public ElingOA6_DSJCJ.Model.Config DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.Config model = new ElingOA6_DSJCJ.Model.Config();
            if (row != null)
            {
                if (row["FKeyName"] != null)
                {
                    model.FKeyName = row["FKeyName"].ToString();
                }
                if (row["FConfigClass"] != null)
                {
                    model.FConfigClass = row["FConfigClass"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDesc"] != null)
                {
                    model.FDesc = row["FDesc"].ToString();
                }
                if (row["FKeyValue"] != null)
                {
                    model.FKeyValue = row["FKeyValue"].ToString();
                }
                if (row["FIsWithDocCls"] != null)
                {
                    model.FIsWithDocCls = row["FIsWithDocCls"].ToString();
                }
                if (row["FShowText"] != null)
                {
                    model.FShowText = row["FShowText"].ToString();
                }
                if (row["FSeq"] != null)
                {
                    model.FSeq = row["FSeq"].ToString();
                }
                if (row["FIsUse"] != null)
                {
                    model.FIsUse = row["FIsUse"].ToString();
                }
            }
            return model;
        }

    }
}
